<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idcard">
        <el-input
          v-model="queryParams.idcard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="政治面貌" prop="politics">
        <el-input
          v-model="queryParams.politics"
          placeholder="请输入政治面貌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学历" prop="degree">
        <el-input
          v-model="queryParams.degree"
          placeholder="请输入学历"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['evaluation:member:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['evaluation:member:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['evaluation:member:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['evaluation:member:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="memberList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" align="center" width="45" prop="sn"/>
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="身份证号" align="center" min-width="160" prop="idcard"/>
      <el-table-column label="性别" align="center" width="50" prop="sex"/>
      <el-table-column label="出生年月" align="center" width="75" prop="birthday"/>
      <el-table-column label="民族" align="center" width="60" prop="ethnicity"/>
      <el-table-column label="工作单位及职务" align="center" width="180" prop="workplace"/>
      <el-table-column label="政治面貌" align="center" width="80" prop="politics"/>
      <el-table-column label="学历" align="center" width="70" prop="degree"/>
      <el-table-column label="籍贯" align="center" prop="origin"/>
      <el-table-column label="政治安排" align="center" prop="arrange"/>
      <el-table-column label="社会职务" align="center" prop="position"/>
      <el-table-column label="身份类别" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_eval_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="手机号码" align="center" width="110" prop="phone"/>
      <el-table-column label="结果" align="center" width="68" prop="score">
        <template slot-scope="scope">
          <el-tag type="success">{{ scope.row.score ? scope.row.score : '未评价' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="审核" align="center" prop="audit"/>
      <el-table-column label="参与评价" align="center" prop="evaluate"/>
      <el-table-column label="操作" align="center" fixed="right" width="155px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['evaluation:member:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['evaluation:member:remove']"
          >删除
          </el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
                       v-hasPermi="['evaluation:member:setting', 'evaluation:user:evaluation']">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="handleSetting" icon="el-icon-setting"
                                v-hasPermi="['evaluation:member:setting']">单位设置
              </el-dropdown-item>
              <el-dropdown-item command="handleSelfEvaluation" icon="el-icon-circle-check"
                                v-hasPermi="['evaluation:member:evaluation']">自我评价
              </el-dropdown-item>
              <el-dropdown-item command="handleEvaluation" icon="el-icon-circle-check"
                                v-hasPermi="['evaluation:member:evaluation']">综合评价
              </el-dropdown-item>
              <el-dropdown-item command="handleOverview" icon="el-icon-medal-1"
                                v-hasPermi="['evaluation:member:overview']">评价总览
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改待评价人员对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="980px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="序号" prop="sn">
              <el-input type="number" v-model="form.sn" placeholder="请输入序号" clearable/>
            </el-form-item>
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名"/>
            </el-form-item>
            <el-form-item label="身份证号" prop="idcard">
              <el-input v-model="form.idcard" placeholder="请输入身份证号码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="头像" prop="avatar">
              <image-upload :limit="1" :isShowTip="false" v-model="form.avatar"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择性别">
                <el-option
                  v-for="dict in dict.type.sys_eval_sex"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出生年月" prop="birthday">
              <el-date-picker
                v-model="form.birthday"
                type="month"
                value-format="yyyy-MM"
                placeholder="选择出生年月"
                style="width: 100%">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="民族" prop="ethnicity">
              <el-select v-model="form.ethnicity" filterable clearable placeholder="请选择民族">
                <el-option
                  v-for="dict in dict.type.sys_eval_ethnicity"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="政治面貌" prop="politics">
              <el-select v-model="form.politics" clearable placeholder="请选择政治面貌">
                <el-option
                  v-for="dict in dict.type.sys_eval_politics"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="学历" prop="degree">
              <el-select v-model="form.degree" clearable placeholder="请选择学历">
                <el-option
                  v-for="dict in dict.type.sys_eval_qualification"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="籍贯" prop="origin">
              <el-input v-model="form.origin" placeholder="请输入籍贯"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="工作单位及职务" prop="workplace">
              <el-input v-model="form.workplace" type="textarea" :rows="3" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="政治安排" prop="arrange">
              <el-input v-model="form.arrange" placeholder="请输入政治安排"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="社会职务" prop="position">
              <el-input v-model="form.position" placeholder="请输入社会职务"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入手机号码"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份类别" prop="type">
              <el-select v-model="form.type" clearable placeholder="请选择身份类别">
                <el-option
                  v-for="dict in dict.type.sys_eval_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核" prop="audit">
              <el-switch
                v-model="form.audit"
                active-value="是"
                inactive-value="否"
                active-color="#13ce66"
              ></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参与评价" prop="evaluation">
              <el-switch
                v-model="form.evaluation"
                active-value="是"
                inactive-value="否"
                active-color="#13ce66"
              ></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 评价单位设置-->
    <el-dialog title="评价单位设置" :visible.sync="deptOpen" width="980px" append-to-body>
      <div class="member-header"><span class="member-username">{{ deptForm.username }}</span><span>—参评单位设置</span></div>
      <div class="member-body">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane v-for="ev in evaluateList" :key="ev.id" :name="ev.id + '_' + ev.sn"
                       :label="ev.sn + '、' + ev.name">
            <el-checkbox-group v-model="deptForm.deptIds">
              <el-checkbox v-for="item in deptList" :key="item.deptId" :label="item.deptId" border size="medium"
                           style="margin-bottom: 5px">
                {{ item.deptName }}
              </el-checkbox>
            </el-checkbox-group>
            <div class="member-select-button">
              <el-button @click="onSelected" plain>全选</el-button>
              <el-button @click="onUnSelect" plain>全不选</el-button>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitDeptForm">确 定</el-button>
        <el-button @click="deptCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 自我评价 -->
    <el-dialog title="自我评价" :visible.sync="selfEvaluteOpen" width="680px" append-to-body>
      <el-form ref="form" :model="selfEvalutationForm" label-width="220px">
        <el-form-item :label="ev.sn + '、' + ev.evalItemName" v-for="ev in selfEvalutationList" :key="ev.id" :rules="[{
                    required: true,
                    message: '请选择评价结果',
                    trigger: 'blur',
                  }]">
          <el-select v-model="ev.score" placeholder="请选择" style="width: 100%">
            <el-option label="A" value="A"></el-option>
            <el-option label="B" value="B"></el-option>
            <el-option label="C" value="C"></el-option>
            <el-option label="D" value="D"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="说明">
          <el-input type="textarea" v-model="selfEvalutationForm.content" placeholder="请输入说明内容"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="selfEvaluationFormSubmit">确 定</el-button>
        <el-button @click="selfEvaluteOpen = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 综合评价 -->
    <el-dialog title="综合评价" :visible.sync="evaluteOpen" width="980px" append-to-body>
      <el-tabs v-model="evaluteActiveName" type="border-card" @tab-click="handleEvaluteClick">
        <el-tab-pane v-for="ev in evaluateList" :key="ev.id" :name="ev.id + '_' +ev.sn" :label="ev.sn + '、' + ev.name">
          <el-descriptions class="margin-top" :column="3" size="medium">
            <template slot="title"><span style="color: rgb(234 177 65)">{{ ev.sn + '、' + ev.name }}</span></template>
            <el-descriptions-item :label="index + 1 + '、' + item.deptName" v-for="(item, index) in evaluateItems">
              <span style="color: #1c84c6">评价 {{ item.score }}</span>
            </el-descriptions-item>
          </el-descriptions>
          <el-descriptions>
            <el-descriptions-item :span="3" label="其中" labelStyle="color:rgb(234 177 65)">
              {{ evaluateTips }}
            </el-descriptions-item>
            <el-descriptions-item :span="3" label="自我评价" labelStyle="color:rgb(234 177 65)">
              本项为{{ selfEvaluate }}
            </el-descriptions-item>
          </el-descriptions>
        </el-tab-pane>
        <div style="margin-top: 20px;">
          <el-form ref="form" :model="evaluationForm" label-width="160px" :rules="evaluationRules">
            <el-form-item label="本项综合评价结果" prop="score">
              <el-select v-model="evaluationForm.score" placeholder="请选择评价结果">
                <el-option label="A" value="A"></el-option>
                <el-option label="B" value="B"></el-option>
                <el-option label="C" value="C"></el-option>
                <el-option label="D" value="D"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="说明">
              <el-input type="textarea" v-model="evaluationForm.content"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="evaluationFormSubmit">保存</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-tabs>
      <div style="margin-top: 20px;">
        <el-form ref="form" :model="zhEvaluationForm" label-width="180px" :rules="zhEvaluationRules">
          <el-form-item :label="'对' + zhEvaluationForm.name + '综合评价结果'" prop="score">
            <el-select v-model="zhEvaluationForm.score" placeholder="请选择">
              <el-option label="A" value="A"></el-option>
              <el-option label="B" value="B"></el-option>
              <el-option label="C" value="C"></el-option>
              <el-option label="D" value="D"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="说明">
            <el-input type="textarea" v-model="zhEvaluationForm.ext1"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="zhEvaluationFormSubmit">确 定</el-button>
        <el-button @click="evaluteOpen = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 评价总览-->
    <el-drawer
      title="评价总览"
      :visible.sync="drawer"
      size="50%"
      direction="rtl">
      <el-descriptions style="padding: 0px 15px;" labelClassName="custom-label" title="张三的综合评价" :column="3"
                       size="medium" border>
        <el-descriptions-item label="姓名">{{ form.name }}</el-descriptions-item>
        <el-descriptions-item label="性别">{{ form.sex }}</el-descriptions-item>
        <el-descriptions-item label="手机号">{{ form.phone }}</el-descriptions-item>
        <el-descriptions-item label="出生年月">{{ form.birthday }}</el-descriptions-item>
        <el-descriptions-item label="名族">{{ form.ethnicity }}</el-descriptions-item>
        <el-descriptions-item label="政治面貌">{{ form.politics }}</el-descriptions-item>
        <el-descriptions-item label="学历">{{ form.degree }}</el-descriptions-item>
        <el-descriptions-item label="籍贯">{{ form.origin ? form.origin : '无' }}</el-descriptions-item>
        <el-descriptions-item label="政治安排">{{ form.arrange ? form.arrange : '无' }}</el-descriptions-item>
        <el-descriptions-item label="社会职务">{{ form.position ? form.position : '无' }}</el-descriptions-item>
        <el-descriptions-item label="身份证号码">{{ form.idcard ? form.idcard : '无' }}</el-descriptions-item>
        <el-descriptions-item label="身份类别">
          <dict-tag
            :options="dict.type.sys_eval_type"
            :value="form.type"
          />
        </el-descriptions-item>
        <el-descriptions-item label="工作单位及职务">{{ form.workplace }}</el-descriptions-item>
      </el-descriptions>
      <!-- 评价结果-->
      <el-descriptions style="padding: 15px 15px;" labelClassName="custom-label-2" :column="1" size="medium" border>
        <el-descriptions-item :label="item.evaluateName" v-for="item in overviewForm">
          单位：{{ item.deptContent ? item.deptContent : '暂无评价' }}，
          自我评价：{{ item.selfScore ? item.selfScore : '无' }}，综合评价：<span
          style="color: red;font-weight: bold">{{
            item.comScore ? item.comScore : '无'
          }}</span>{{ item.comContent ? "(说明：" + item.comContent + ")" : "" }}
        </el-descriptions-item>
        <el-descriptions-item label="综合评价结果"><span style="color: red;font-weight: bold">{{ form.score }}</span>
          {{ form.ext1 ? "(说明：" + form.ext1 + ")" : "" }}
        </el-descriptions-item>
      </el-descriptions>
    </el-drawer>
  </div>
</template>

<script>
import {
  listMember,
  getMember,
  delMember,
  addMember,
  updateMember,
  getEvaluationItems,
  updateComEvaluation,
  overview
} from "@/api/evaluation/member";
import {listDept} from "@/api/system/dept"
import {listAll} from "@/api/evaluation/evaluate"
import {listEvaluationByMemberId, saveEvaluation} from "@/api/evaluation/selfEvaluation"
import {saveComEvaluation} from "@/api/evaluation/comEvaluation"
import {addEvaluation, updateEvaluation, listAllEvaluation} from "@/api/evaluation/memberEvaluation"

export default {
  name: "Member",
  dicts: ['sys_eval_sex', 'sys_eval_type', 'sys_eval_politics', 'sys_eval_qualification', 'sys_eval_ethnicity'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 待评价人员表格数据
      memberList: [],
      // 评价单位
      deptList: [],
      // 评价项目
      evaluateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        idcard: null,
        sn: null,
        sex: null,
        birthday: null,
        ethnicity: null,
        politics: null,
        degree: null,
        origin: null,
        workplace: null,
        arrange: null,
        position: null,
        avatar: null,
        phone: null,
        type: null,
        audit: null,
        evaluate: null,
        ext1: null,
        ext2: null
      },
      imageUrl: '',
      // 表单参数
      form: {
        name: null,
        idcard: null,
        sn: null,
        sex: null,
        birthday: null,
        ethnicity: null,
        politics: null,
        degree: null,
        origin: null,
        workplace: null,
        arrange: null,
        position: null,
        avatar: null,
        phone: null,
        type: null,
        audit: null,
        evaluate: null,
        score: null,
        ext1: null,
        ext2: null
      },
      //评价单位设置
      deptOpen: false,
      activeName: null,
      deptForm: {
        id: null,
        deptIds: [],
        username: null,
      },
      //自我评价
      selfEvaluteOpen: false,
      selfEvalutationForm: {},
      selfEvalutationList: [],
      //综合评价
      evaluteOpen: false,
      evaluteForm: {},
      evaluteActiveName: null,
      evaluationForm: {
        memberId: null,
        username: null,
        score: null,
        content: null,
      },
      zhEvaluationForm: {
        memberId: null,
        score: null,
        ext1: null,
      },
      evaluateItems: [],
      evaluateTips: null,
      selfEvaluate: null,
      //评价总览
      drawer: false,
      overviewForm: {},
      // 表单校验
      rules: {
        name: [
          {required: true, message: "姓名不能为空", trigger: "blur"}
        ],
        idcard: [
          {required: true, message: "身份证号码不能为空", trigger: "blur"},
          {
            pattern: /(^[1-9]\d{5}(19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
            message: "请输入正确的身份证号码",
            trigger: "blur"
          }
        ],
        sn: [
          {required: true, message: "序号不能为空", trigger: "blur"}
        ],
        sex: [
          {required: true, message: "性别不能为空", trigger: "blur"}
        ],
        birthday: [
          {required: true, message: "出生日期不能为空", trigger: "blur"}
        ],
        ethnicity: [
          {required: true, message: "民族不能为空", trigger: "blur"}
        ],
        politics: [
          {required: true, message: "政治面貌不能为空", trigger: "blur"}
        ],
        degree: [
          {required: true, message: "学历不能为空", trigger: "blur"}
        ],
        origin: [
          {required: true, message: "籍贯不能为空", trigger: "blur"}
        ],
        phone: [
          {required: true, message: "手机号码不能为空", trigger: "blur"},
          {
            pattern: /^1[3|4|5|7|8][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur"
          }
        ],
        type: [
          {required: true, message: "身份类别不能为空", trigger: "blur"}
        ],
        score: [{
          required: true,
          message: '请选择评价分数',
          trigger: 'blur'
        }]
      },
      evaluationRules: {
        score: [{
          required: true,
          message: '请选择评价分数',
          trigger: 'blur'
        }]
      },
      zhEvaluationRules: {
        score: [{
          required: true,
          message: '请选择评价分数',
          trigger: 'blur'
        }]
      }
    };
  },
  created() {
    this.getList();
    this.getEvaluateList();
  },
  methods: {
    /** 查询待评价人员列表 */
    getList() {
      this.loading = true;
      listMember(this.queryParams).then(response => {
        this.memberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //头像上传成功
    handleAvatarSuccess() {

    },
    // 头像上传之前
    beforeAvatarUpload() {

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        idcard: null,
        sn: null,
        sex: null,
        birthday: null,
        ethnicity: null,
        politics: null,
        degree: null,
        origin: null,
        workplace: null,
        arrange: null,
        position: null,
        avatar: null,
        phone: null,
        type: null,
        audit: null,
        evaluate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        ext1: null,
        ext2: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加待评价人员";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMember(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改待评价人员";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMember(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMember(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除待评价人员编号为"' + ids + '"的数据项？').then(function () {
        return delMember(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('evaluation/member/export', {
        ...this.queryParams
      }, `member_${new Date().getTime()}.xlsx`)
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        //单位设置
        case "handleSetting":
          this.handleSetting(row);
          break;
        //自我评价
        case "handleSelfEvaluation":
          this.handleSelfEvaluation(row);
          break;
        //综合评价
        case "handleEvaluation":
          this.handleEvaluation(row);
          break;
        //评价总览
        case "handleOverview":
          this.handleOverview(row);
          break;
        default:
          break;
      }
    },
    //评价单位设置
    handleSetting(row) {
      //优先查询是否已设置
      let evaluateId = this.activeName.split("_")[0];
      listAllEvaluation({memberId: row.id, evaluateId: evaluateId}).then((res) => {
        if (res.data && res.data.length > 0) {
          this.deptForm.deptIds = res.data.map(item => item.deptId);
        }
        this.deptOpen = true;
      });
      this.getDeptList(evaluateId);
      this.deptForm.username = row.name;
      this.deptForm.evaluateId = evaluateId;
      this.deptForm.memberId = row.id;
    },
    //查询评价单位
    getDeptList(evaluateId) {
      listDept({evIds: evaluateId}).then((res) => {
        this.deptList = res.data;
      })
    },
    //查询评价项目
    getEvaluateList() {
      listAll().then((res) => {
        this.evaluateList = res.data;
        if (res.data && res.data.length > 0) {
          this.activeName = res.data[0].id + "_" + res.data[0].sn;
          this.evaluteActiveName = res.data[0].id + "_" + res.data[0].sn;
        }
      })
    },
    // 切换评价项目
    handleClick(tab, event) {
      let evaluateId = tab.name.split("_")[0];
      this.deptForm.deptIds = [];
      //优先查询是否已设置
      listAllEvaluation({memberId: this.deptForm.memberId, evaluateId: evaluateId}).then((res) => {
        if (res.data && res.data.length > 0) {
          this.deptForm.deptIds = res.data.map(item => item.deptId);
        }
      });
      this.getDeptList(evaluateId) ;
      this.deptForm.evaluateId = evaluateId;
    },
    // 提交评价单位
    submitDeptForm() {
      if (this.deptForm.deptIds && this.deptForm.deptIds.length > 0) {
        if (this.deptForm.id == null) {
          addEvaluation(this.deptForm).then(response => {
            this.$modal.msgSuccess("评价单位设置成功！");
          });
        } else {
          updateEvaluation(this.deptForm).then(response => {
            this.$modal.msgSuccess("评价单位设置成功！");
          });
        }
      } else {
        this.$modal.msgError("请选择评价单位！");
      }
    },
    //全选
    onSelected() {
      this.deptForm.deptIds = this.deptList.map(item => item.deptId);
    },
    //全不选
    onUnSelect() {
      this.deptForm.deptIds = [];
    },
    // 评价单位取消
    deptCancel() {
      this.deptOpen = false;
    },
    //打开自我评价
    handleSelfEvaluation(row) {
      this.selfEvaluteOpen = true;
      this.getListSelfEvaluation(row.id);
    },
    //查询自我评价信息
    getListSelfEvaluation(memberId) {
      this.selfEvalutationForm.memberId = memberId;
      listEvaluationByMemberId(memberId).then((res) => {
        this.selfEvalutationList = res.data;
        if (res.data && res.data.length > 0) {
          this.selfEvalutationForm.content = res.data[0].content;
        }
      });
    },
    //保存自我评价
    selfEvaluationFormSubmit() {
      let that = this;
      this.selfEvalutationList.forEach((item) => {
        item.content = that.selfEvalutationForm.content;
      });
      saveEvaluation(this.selfEvalutationList, this.selfEvalutationForm.memberId).then((res) => {
        this.$modal.msgSuccess("评价单位设置成功！");
        this.selfEvaluteOpen = false;
        this.getList();
      });
    },
    //打开综合评价弹窗
    handleEvaluation(row) {
      let evaluateId = this.evaluteActiveName.split("_")[0];
      this.evaluationForm.memberId = row.id;
      this.zhEvaluationForm.memberId = row.id;
      this.zhEvaluationForm.name = row.name;
      this.evaluteOpen = true;
      this.getEvaluationItems(row.id, evaluateId);
    },
    //切换评价
    handleEvaluteClick(tab, event) {
      let evaluateId = this.evaluteActiveName.split("_")[0];
      this.getEvaluationItems(this.zhEvaluationForm.memberId, evaluateId);
    },
    getEvaluationItems(memberId, evaluateId) {
      const this_ = this;
      getEvaluationItems({"memberId": memberId, "evaluateId": evaluateId}).then(res => {
        this_.evaluateItems = res.data.evaluationItems;
        if (res.data.member) {
          var member = res.data.member;
          this_.zhEvaluationForm.name = member.name;
          this_.zhEvaluationForm.score = member.score;
          this_.zhEvaluationForm.ext1 = member.ext1;
          this_.zhEvaluationForm.memberId = member.id;
        }

        if (res.data.selfEvaluation) {
          this_.selfEvaluate = res.data.selfEvaluation.score;
        }
        this_.evaluationForm = res.data.comEvaluation ? res.data.comEvaluation : {};
        //计算统计各个评价项
        let AScore = 0, BScore = 0, CScore = 0, DScore = 0;
        this_.evaluateItems.forEach(item => {
          switch (item.score) {
            case "A":
              AScore++;
              break;
            case "B":
              BScore++;
              break;
            case "C":
              CScore++;
              break;
            case "D":
              DScore++;
              break;
            default:
              break;
          }
        });
        let evaluation = "";
        if (AScore != 0) {
          evaluation = evaluation + "评价A" + AScore + "个";
        }
        if (BScore != 0) {
          evaluation = evaluation + "评价B" + BScore + "个";
        }
        if (CScore != 0) {
          evaluation = evaluation + "评价C" + CScore + "个";
        }
        if (DScore != 0) {
          evaluation = evaluation + "评价D" + DScore + "个";
        }
        this_.evaluateTips = evaluation;
      })
    },
    //提交单项评价结果
    evaluationFormSubmit() {
      let memberId = this.zhEvaluationForm.memberId;
      let evaluateId = this.evaluteActiveName.split("_")[0];
      let score = this.evaluationForm.score;
      let content = this.evaluationForm.content;
      saveComEvaluation(memberId, evaluateId, score, content).then((res) => {
        this.$modal.msgSuccess("评价提交成功！");
      });
    },
    //提交综合评价结果
    zhEvaluationFormSubmit() {
      let memberId = this.zhEvaluationForm.memberId;
      let score = this.zhEvaluationForm.score;
      let content = this.zhEvaluationForm.ext1;
      updateComEvaluation(memberId, score, content).then((res) => {
        this.evaluteOpen = false;
        this.$modal.msgSuccess("评价提交成功！");
        this.getList();
      })
    },
    //打开综合评价总览
    handleOverview(row) {
      overview(row.id).then((res) => {
        this.drawer = true;
        this.form = res.data.member;
        this.overviewForm = res.data.overviewEvalutionVos;
      });
    },
  }
};
</script>
<style lang="scss">
.custom-label {
  width: 120px;
}

.custom-label-2 {
  width: 50%;
}
</style>
<style lang="scss" scoped>
.member-header {
  margin-bottom: 10px;
  text-align: center;
  font-size: 20px;
  font-weight: 600;

  .member-username {
    color: red;
    margin-right: 5px;
  }
}

.member-select-button {
  text-align: center;
  margin-top: 20px;
}
</style>
